package de.lgohlke.serializer;

import com.thoughtworks.xstream.XStream;

/**
 * <p>XStreamSerializer class.</p>
 *
 * @author lars
 * @version $Id: $
 */
public class XStreamSerializer<T> implements ISerializer<T>
{
  private final XStream xStream = new XStream();

  /**
   * <p>serialize.</p>
   *
   * @param data a T object.
   * @param <T> a T object.
   * @return an array of byte.
   */
  public byte[] serialize(final T data)
  {
    return xStream.toXML(data).getBytes();
  }

  /**
   * <p>deserialize.</p>
   *
   * @param data an array of byte.
   * @return a T object.
   */
  @SuppressWarnings("unchecked")
  public T deserialize(final byte[] data)
  {
    return (T) xStream.fromXML(new String(data));
  }

}
